import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:juming_test/model/domain/domain_filter_item_model.dart';
import 'package:juming_test/model/domain/domain_filter_option_model.dart';
import 'package:juming_test/module/domain/domain_filter/widgets/domain_filter_option.dart';

/// 多组选项按钮单选组件
class DomainFilterOptionGroup extends StatelessWidget {
  const DomainFilterOptionGroup({
    super.key,
    required this.list,
    required this.onChanged,
  });

  // 数据源
  final List<DomainFilterItemModel> list;
  // 选中回调
  final Function(List<DomainFilterOptionModel>) onChanged;

  @override
  Widget build(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        ...list.map((item) {
          return Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              if (item.name.isNotEmpty)
                Text(
                  item.name,
                  style: TextStyle(
                    fontSize: 16.sp,
                    fontWeight: FontWeight.bold,
                  ),
                ),
              SizedBox(height: 8.h),
              DomainFilterOption(
                model: item,
                onChanged: (list) => onChanged(list),
              ),
              SizedBox(height: 8.h),
            ],
          );
        }),
      ],
    );
  }
}
